<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Skornyakov Anatoliy
 * Date: 30.05.13
 * Time: 14:14
 * 
 */

class IndexController extends Zend_Controller_Action
{
    public function init()
    {
        $this->_helper->getHelper('AjaxContext')
            ->addActionContext('get-city-list', 'json')
            ->addActionContext('get-metro-list', 'json')
            ->initContext();
    }

    public function indexAction()
    {
        $this->view->fUser    = new Zftest_Form_User();

        if ($this->getRequest()->isPost() && $this->view->fUser->isValid($this->getRequest()->getPost())) {

        }
        $this->view->fCompany = new Zftest_Form_Company();
    }

    public function metroAction()
    {
        $this->view->fMetro = new Zftest_Form_Metro();

    }

    public function getCityListAction()
    {
        $this->view->identifier = 'id';
        $this->view->label      = 'name';

        $this->view->items = array(
            array('id' => 1, 'name' => 'Москва'),
            array('id' => 2, 'name' => 'Спб'),
        );
    }

    public function getMetroListAction()
    {
        $cityId = (int)$this->_getParam('cityId', 1);

        $this->view->identifier = 'id';
        $this->view->label      = 'name';

        $metro = array(
            1 => array(
                array('id' => 1, 'name' => 'Метро №1 (Мск)'),
                array('id' => 2, 'name' => 'Метро №2 (Мск)'),
                array('id' => 3, 'name' => 'Метро №3 (Мск)'),
                array('id' => 4, 'name' => 'Метро №4 (Мск)'),
                array('id' => 5, 'name' => 'Метро №5 (Мск)')
            ),
            2 => array(
                array('id' => 6, 'name' => 'Метро №1 (Спб)'),
                array('id' => 7, 'name' => 'Метро №2 (Спб)'),
                array('id' => 8, 'name' => 'Метро №3 (Спб)'),
                array('id' => 9, 'name' => 'Метро №4 (Спб)'),
                array('id' => 10, 'name' => 'Метро №5 (Спб)'),
                array('id' => 11, 'name' => 'Метро №6 (Спб)')
            )
        );

        $this->view->items = (isset($metro[$cityId])) ? $metro[$cityId] : array();
    }
}